<template>
	<view class="content">
		<view class="Title">
			<view class="Left">
				充值到
			</view>
			<view class="Right">
				我的钱包
			</view>
		</view>
		<view class="content-top"
			style="margin: 0 30rpx;padding: 25rpx 30rpx;background-color: #202226;height: 197rpx;border-radius: 20rpx;">
			<view class='cell-item-hd' style="margin-bottom: 50rpx;">
				<view class='cell-hd-title'>充值金额</view>
			</view>
			<view>
				<input class='cell-bd-input' placeholder='请输入要充值的金额' v-model="recharge" focus type="digit"
					style="font-size: 38rpx;color: #fff;"></input>
			</view>
		</view>
		<view class="Item" v-for="A,B in payments" :key="B" @click="ChangeIndex(B)"
			style="display: flex;align-items: center;padding: 27rpx 35rpx;margin: 10rpx 30rpx;background-color: #202226;border-radius: 20rpx;">
			<image :src="A.icon" mode="" style="width: 66rpx;height: 66rpx;margin-right: 30rpx;"></image>
			<view style="flex: 1;color: #fff;">
				{{A.name}}
			</view>
			<view v-if="B === selected">
				<image src="/static/se.png" style="width: 24rpx;height: 24rpx;" mode=""></image>
			</view>
			<view v-else>
				<image src="/static/nose.png" style="width: 24rpx;height: 24rpx;" mode=""></image>
			</view>
		</view>
		<view class="UP" v-if="off">
			<view class="UPTitle">
				线下支付请上传您的转账记录
			</view>
			<view class="UPInfo">
				<view class="u1">
					<view class="L">
						银行卡号:{{yhk.num}}
					</view>
					<view class="R" @click="Copy(yhk.num)">
						点击复制
					</view>
				</view>
				<view class="u1">
					<view class="L">
						银行:{{yhk.bank}}
					</view>
					<view class="R" @click="Copy(yhk.bank)">
						点击复制
					</view>
				</view>
				<view class="u1">
					<view class="L">
						公司名称:{{yhk.bankads}}
					</view>
					<view class="R" @click="Copy(yhk.bankads)">
						点击复制
					</view>
				</view>
			</view>
			<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="1">
				<image src="/static/sy.png" style="width: 154rpx;height: 154rpx;"></image>
			</u-upload>

		</view>
		<view style="box-shadow: none;position: fixed;bottom: 94rpx;left: 61rpx;">
			<button
				style="width: 629rpx;height: 75rpx;background: linear-gradient(180deg, #F2D7AA 0%, #DEBC86 100%);border-radius: 10rpx;font-weight: bold;color: #000;font-size: 32rpx;"
				hover-class="btn-hover2" @click="navigateToHandle">立即充值</button>
		</view>
	</view>
</template>

<script>
	import {
		baseUrl,
		apiBaseUrl
	} from '@/config/config.js';
	// #ifndef H5
	const module = uni.requireNativePlugin('SandPayTypeModule')
	// #endif
	export default {
		data() {
			return {
				user: {}, // 用户信息
				payments: [], // 可用充值方式列表
				recharge: '', // 充值的金额
				orderType: 2, // 充值类型
				selected: -1,
				type: 2,
				yhk: {},
				fileList1: [],
				off: false,
				paystatus:true,
			}
		},
		onLoad() {
			this.userInfo()
			this.getlist()
		},
		methods: {
			Copy(e) {
				uni.setClipboardData({
					data: e, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							title: '复制成功'
						})
					}
				});
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},

			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: apiBaseUrl + 'api.html', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							'method': 'images.upload',
							'upfile': url
						},
						success: (res) => {
							//如果要路径在这里修改
							resolve(JSON.parse(res.data).data.image_id)
						}
					});
				})
			},

			ChangeIndex(e) {
				let that = this
				if (that.payments[e].code === 'offline') {
					that.off = true
				} else {
					that.off = false
				}
				that.selected = e
			},
			getlist() {
				this.$api.paymentList({}, res => {
					res.data.forEach((A, B) => {
						if (A.code === 'balancepay') {
							this.yhk = A
						}
					})
					this.payments = this.formatPayments(res.data)
				})
			},
			// 支付方式处理
			formatPayments(payments) {
				// h5支付并且是在微信浏览器内 过滤支付宝支付
				if (this.$common.isWeiXinBrowser()) {
					let payments1 = payments.filter(item => item.code !== 'alipay')
				}

				// 如果是充值订单 过滤余额支付 过滤非线上支付方式
				let payments1 = payments.filter(
					item => item.code !== "balancepay" || item.is_online === 2
				)

				// 设置logo图片
				payments1.forEach(item => {
					this.$set(item, 'icon', '/static/image/' + item.code + '.png')
				})
				return payments1
			},
			// 获取用户信息
			userInfo() {
				this.$api.userInfo({}, res => {
					if (res.status) {
						this.user = res.data
					}
				})
			},
			// 去充值
			navigateToHandle() {
				let that = this
				if (!Number(this.recharge)) {
					that.$common.errorToShow('请输入要充值的金额')
				} else {
					// this.$common.navigateTo('/pages/goods/payment/index?recharge=' + Number(this.money) + '&type=' + this
					// 	.orderType)
					if (that.payments[that.selected]) {
						that.toPayHandler(that.payments[that.selected].code)
					} else {
						uni.showToast({
							title: '请选择支付方式',
							icon: 'none'
						})
					}
				}

			},
			redirectHandler() {
				this.$common.redirectTo('/pages/member/balance/index')
			},
			// **-----------------------------------
			toPayHandler(code) {
				let _this = this
				if(this.paystatus==true)
				{
					this.paystatus = false
				}else{
					return;
				}
				let data = {
					payment_code: code,
					payment_type: _this.type
				}
				let trade_type = 'APP'
				// #ifdef H5
				trade_type = 'WAP'
				// #endif

				data['ids'] = this.user.id
				if ((this.type == 5 || this.type == 6) && this.recharge) {
					data['params'] = {
						trade_type: 'APP',
						// formid: this.orderId
					}
				}
				switch (code) {
					case 'sxypay':
						data['params'] = {
							trade_type: 'APP',
							money: _this.recharge,
							payerName: this.payerName,
							idType: this.idType,
							idNum: this.idNum,
							bankCardNum: this.bankCardNum,
							email: this.email,

						}
						_this.$api.pay(data, res => {
							if (res.status) {
								// #ifndef H5
								plus.runtime.openURL(res.data)
								setTimeout(() => {
									uni.navigateBack()
								}, 1000)
								// #endif
								// #ifdef H5
								if (this.$common.isWeiXinBrowser()) {
									window.location.href = res.data
								} else {
									window.location.href = res.data
								}
								// #endif
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})

						break
					case 'alipaywap':
						if (this.type == 1 && this.orderId) {
							data['params'] = {
								trade_type: 'WAP',
								return_url: baseUrl +
									'wapp/pages/goods/payment/result'
							}
						} else if (this.type == 2 && this.recharge) {
							data['params'] = {
								money: this.recharge,
								recharge_id: this.recharge_id,
								return_url: baseUrl + 'wapp/pages/goods/payment/result'
							}
						} else if ((this.type == 5 || this.type == 6) && this.recharge) {
							data['params'] = {
								formid: this.orderId
							}
						}

						this.$api.pay(data, res => {

							if (res.status) {
								const url = res.data.url
								const data = res.data.data

								// #ifdef H5
								window.location.href = apiBaseUrl + 'b2c/index/alipaywap?' + data
								// #endif

								// #ifdef APP
								plus.runtime.openURL(apiBaseUrl + 'b2c/index/alipaywap?' + data)
								// #endif

							} else {
								this.paystatus=true;
								this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'alipay':
						console.log('2')
						/**
						 * 支付宝支付需要模拟GET提交数据
						 */


						if (_this.type == 1 && _this.orderId) {
							data['params'] = {
								trade_type: trade_type
							}
						} else if (_this.type == 2 && _this.recharge) {
							data['params'] = {
								trade_type: trade_type,
								money: _this.recharge
							}
						}

						_this.$api.pay(data, res => {

							if (res.status) {
								const url = res.data.url
								const data = res.data.data
								// #ifdef H5
								let tempForm = document.createElement('form')
								tempForm.id = 'aliPay'
								tempForm.methods = 'post'
								tempForm.action = url
								tempForm.target = '_self'
								let input = []
								for (let k in data) {
									input[k] = document.createElement('input')
									input[k].type = 'hidden'
									input[k].name = k
									input[k].value = data[k]
									tempForm.appendChild(input[k])
								}
								tempForm.addEventListener('submit', function() {}, false)
								document.body.appendChild(tempForm)
								tempForm.dispatchEvent(new Event('submit'))
								tempForm.submit()
								document.body.removeChild(tempForm)
								// #endif

								// #ifdef APP
								uni.requestPayment({
									provider: "alipay",
									orderInfo: res.data.data,
									success: function(data) {
										_this.$common.successToShow('支付成功', () => {
											_this.redirectHandler(res.data.payment_id)
										})
									}
								});
								// #endif
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'alipayds':
						console.log('2')
						/**
						 * 支付宝支付需要模拟GET提交数据
						 */

						if (_this.type == 1 && _this.orderId) {
							data['params'] = {
								trade_type: trade_type
							}
						} else if (_this.type == 2 && _this.recharge) {
							data['params'] = {
								trade_type: trade_type,
								money: _this.recharge
							}
						}

						_this.$api.pay(data, res => {

							if (res.status) {
								const url = res.data.url
								const data = res.data.data
								// #ifdef H5
								let tempForm = document.createElement('form')
								tempForm.id = 'aliPay'
								tempForm.methods = 'post'
								tempForm.action = url
								tempForm.target = '_self'
								let input = []
								for (let k in data) {
									input[k] = document.createElement('input')
									input[k].type = 'hidden'
									input[k].name = k
									input[k].value = data[k]
									tempForm.appendChild(input[k])
								}
								tempForm.addEventListener('submit', function() {}, false)
								document.body.appendChild(tempForm)
								tempForm.dispatchEvent(new Event('submit'))
								tempForm.submit()
								document.body.removeChild(tempForm)
								// #endif

								// #ifdef APP
								uni.requestPayment({
									provider: "alipay",
									orderInfo: res.data.data,
									success: function(data) {
										_this.$common.successToShow('支付成功', () => {
											_this.redirectHandler(res.data.payment_id)
										})
									}
								});
								// #endif
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'alipayhh':
						console.log('2')
						/**
						 * 支付宝支付需要模拟GET提交数据
						 */


						if (_this.type == 1 && _this.orderId) {
							data['params'] = {
								trade_type: trade_type
							}
						} else if (_this.type == 2 && _this.recharge) {
							data['params'] = {
								trade_type: trade_type,
								money: _this.recharge
							}
						}

						_this.$api.pay(data, res => {

							if (res.status) {
								const url = res.data.url
								const data = res.data.data
								// #ifdef H5
								let tempForm = document.createElement('form')
								tempForm.id = 'aliPay'
								tempForm.methods = 'post'
								tempForm.action = url
								tempForm.target = '_self'
								let input = []
								for (let k in data) {
									input[k] = document.createElement('input')
									input[k].type = 'hidden'
									input[k].name = k
									input[k].value = data[k]
									tempForm.appendChild(input[k])
								}
								tempForm.addEventListener('submit', function() {}, false)
								document.body.appendChild(tempForm)
								tempForm.dispatchEvent(new Event('submit'))
								tempForm.submit()
								document.body.removeChild(tempForm)
								// #endif

								// #ifdef APP
								uni.requestPayment({
									provider: "alipay",
									orderInfo: res.data.data,
									success: function(data) {
										_this.$common.successToShow('支付成功', () => {
											_this.redirectHandler(res.data.payment_id)
										})
									}
								});
								// #endif
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'alipayhhg':
						console.log('2')
						/**
						 * 支付宝支付需要模拟GET提交数据
						 */


						if (_this.type == 1 && _this.orderId) {
							data['params'] = {
								trade_type: trade_type
							}
						} else if (_this.type == 2 && _this.recharge) {
							data['params'] = {
								trade_type: trade_type,
								money: _this.recharge
							}
						}

						_this.$api.pay(data, res => {
							console.log(res);

							if (res.status) {
								const url = res.data.url
								const data = res.data.data
								// #ifdef H5
								let tempForm = document.createElement('form')
								tempForm.id = 'aliPay'
								tempForm.methods = 'post'
								tempForm.action = url
								tempForm.target = '_self'
								let input = []
								for (let k in data) {
									input[k] = document.createElement('input')
									input[k].type = 'hidden'
									input[k].name = k
									input[k].value = data[k]
									tempForm.appendChild(input[k])
								}
								tempForm.addEventListener('submit', function() {}, false)
								document.body.appendChild(tempForm)
								tempForm.dispatchEvent(new Event('submit'))
								tempForm.submit()
								document.body.removeChild(tempForm)
								// #endif

								// #ifdef APP
								uni.requestPayment({
									provider: "alipay",
									orderInfo: res.data.data,
									success: function(data) {
										_this.$common.successToShow('支付成功', () => {
											_this.redirectHandler(res.data.payment_id)
										})
									}
								});
								// #endif
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'wechatpay':
						// 微信 H5支付
						if (_this.type == 1 && _this.orderId) {
							data['params'] = {
								trade_type: 'APP'
							}
						} else if (_this.type == 2 && _this.recharge) {
							data['params'] = {
								trade_type: 'APP',
								money: _this.recharge
							}
						}

						// 微信app支付
						_this.$api.pay(data, res => {
							console.log(res);
							if (res.status) {
								//console.log(JSON.stringify(res));
								// 调用微信支付  
								uni.requestPayment({
									provider: "wxpay",
									orderInfo: {
										appid: res.data.appid,
										noncestr: res.data.noncestr,
										package: res.data.package,
										partnerid: res.data.partnerid,
										prepayid: res.data.prepayid,
										timestamp: res.data.timestamp,
										sign: res.data.sign,
									},
									success: function(data) {
										_this.$common.successToShow('支付成功', () => {
											_this.redirectHandler(res.data.payment_id)
										})
									},
									fail: function(res) {
										console.log(JSON.stringify(res));
									}
								});
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'wechatpayhh':
						// 微信 H5支付
						if (_this.type == 1 && _this.orderId) {
							data['params'] = {
								trade_type: 'APP'
							}
						} else if (_this.type == 2 && _this.recharge) {
							data['params'] = {
								trade_type: 'APP',
								money: _this.recharge
							}
						}

						// 微信app支付
						_this.$api.pay(data, res => {
							console.log(res);
							if (res.status) {
								//console.log(JSON.stringify(res));
								// 调用微信支付  
								uni.requestPayment({
									provider: "wxpay",
									orderInfo: {
										appid: res.data.appid,
										noncestr: res.data.noncestr,
										package: res.data.package,
										partnerid: res.data.partnerid,
										prepayid: res.data.prepayid,
										timestamp: res.data.timestamp,
										sign: res.data.sign,
									},
									success: function(data) {
										_this.$common.successToShow('支付成功', () => {
											_this.redirectHandler(res.data.payment_id)
										})
									},
									fail: function(res) {
										console.log(JSON.stringify(res));
									}
								});
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'wechatpayds':
						// 微信 H5支付
						if (_this.type == 1 && _this.orderId) {
							data['params'] = {
								trade_type: 'APP'
							}
						} else if (_this.type == 2 && _this.recharge) {
							data['params'] = {
								trade_type: 'APP',
								money: _this.recharge
							}
						}

						// 微信app支付
						_this.$api.pay(data, res => {
							console.log(res);
							if (res.status) {
								//console.log(JSON.stringify(res));
								// 调用微信支付  
								uni.requestPayment({
									provider: "wxpay",
									orderInfo: {
										appid: res.data.appid,
										noncestr: res.data.noncestr,
										package: res.data.package,
										partnerid: res.data.partnerid,
										prepayid: res.data.prepayid,
										timestamp: res.data.timestamp,
										sign: res.data.sign,
									},
									success: function(data) {
										_this.$common.successToShow('支付成功', () => {
											_this.redirectHandler(res.data.payment_id)
										})
									},
									fail: function(res) {
										console.log(JSON.stringify(res));
									}
								});
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'offline':
						/**
						 * 线下支付
						 */
						if (_this.fileList1[0]) {
							_this.$api.chongzhi({
								money: _this.recharge,
								image: _this.fileList1[0].url
							}, res => {
								if (res.status) {
									uni.showToast({
										title: '提交成功',
										icon: 'none'
									})
								}
							})
						} else {
							uni.showToast({
								title: '请上传转账证明',
								icon: 'none'
							})
						}
						break
					case 'shandepay':
						console.log(2)
						data['params'] = {
							trade_type: 'bank',
							money: _this.recharge
						}
						_this.$api.pay(data, res => {
							console.log(3, res)
							if (res.status) {
								// #ifndef H5
								plus.runtime.openURL(res.data)
								setTimeout(() => {
									uni.navigateBack()
								}, 1000)
								// #endif
								// #ifdef H5
								_this.$store.commit('setpayinfo', res)
								uni.redirectTo({
									url: `/pages/webview/index`
								})
								// #endif

							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'sandyunpay':
						var transitUrl = '';
						// #ifdef H5
						transitUrl =
							apiBaseUrl +
							'wapp/pages/goods/payment/auth?recharge=' +
							_this.recharge +
							'&type=' +
							_this.type;
						// #endif
						data['params'] = {
							money: _this.recharge,
							frontUrl: transitUrl
						}
						_this.$api.pay(data, res => {
							if (res.status) {
								// #ifndef H5
								plus.runtime.openURL(res.data)
								setTimeout(() => {
									uni.navigateBack()
								}, 1000)
								// #endif
								// #ifdef H5
								_this.$store.commit('setpayinfo', res)
								uni.redirectTo({
									url: `/pages/webview/index`
								})
								// #endif

							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'sandwechatpay':
						data['params'] = {
							trade_type: 'APP',
							money: _this.recharge
						}
						_this.$api.pay(data, res => {
							if (res.status) {
								console.log(res.data)
								// #ifndef H5
								this.connectSocket();
								module.cashierPaySingle(res.data, ret => {
									if (ret.payType == '1') {
										this.wxPay(ret.tokenId)
									} else {
										this.endLoading()
										if (ret.resultCode == '0000') {
											console.log("支付方式:" + ret.payType)
										}
										console.log("支付结果:" + ret.resultCode)
										console.log("错误信息:" + ret.failReason)
										console.log("action:" + ret.action)
									}
								})
								// #endif
								// #ifdef H5
								_this.$common.errorToShow('暂未开放')

								// #endif

							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})

						break

					case 'adawechatpay':
						// #ifdef H5
						_this.$common.errorToShow('暂未开放')
						return;

						// #endif
						data['params'] = {
							trade_type: 'APP',
							money: _this.recharge
						}
						this.connectSocket();
						plus.share.getServices(shareList => {
							let sweixin = shareList.find(val => val.id == 'weixin')
							if (sweixin) {


								let path = 'pages/adapay/index?payment_type=' + data.payment_type + '&token=' +
									_this.$db.get('userToken') + '&ids=' + data.ids + '&money=' + _this.recharge;
								console.log('path', path)
								sweixin.launchMiniProgram({
									id: 'gh_b25107cbd606', //小程序原始id
									path: path,
									type: 2
								})
								this.endLoading()
							} else {
								uni.showToast({
									icon: 'none',
									title: "未安装微信,无法打开对应小程序"
								})
							}
						}, e => {
							uni.showToast({
								icon: 'none',
								title: "获取微信服务列表失败:" + JSON.stringify(e)
							})
						})
						break
					case 'sandalipayqr':
						data['params'] = {
							trade_type: 'alipay',
							money: _this.recharge
						}
						_this.$api.pay(data, res => {

							if (res.status) {
								// #ifndef H5
								plus.runtime.openURL(res.data)
								setTimeout(() => {
									uni.navigateBack()
								}, 1000)
								// #endif
								// #ifdef H5
								if (this.$common.isWeiXinBrowser()) {
									window.location.href = res.data
								} else {
									window.location.href = res.data
								}
								/* _this.$store.commit('setpayinfo', res)
								uni.redirectTo({
									url: `/pages/webview/index`
								}) */
								// #endif

							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break
					case 'sandjuhe':
						data['params'] = {
							money: _this.recharge
						}
						_this.$api.pay(data, res => {
							// return;

							if (res.status) {


								this.$common.navigateTo('/pages/webview/yunshanfu?url=' + res.data)

							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break

					case 'uijuhepay':
						var transitUrl = '';
						// #ifdef H5
						transitUrl =
							apiBaseUrl +
							'wapp/pages/goods/payment/auth?recharge=' +
							_this.recharge +
							'&type=' +
							_this.type;
						// #endif
						data['params'] = {
							money: _this.recharge,
							frontUrl: transitUrl
						}
						_this.$api.pay(data, res => {

							if (res.status) {

								// #ifdef  APP-PLUS	 || APP-PLUS-NVUE

								plus.runtime.openURL(
									'alipays://platformapi/startapp?appId=20000067&url=' + res
									.data, //这里的appId=20000067是固定的，不需要改
									res => {
										//这里写打开URL地址失败后的处理
										uni.showModal({
											content: '本机未检测到对应客户端，是否打开浏览器访问页面？',
											success: function(res) {
												if (res.confirm) {
													//plus.runtime.openURL();
												}
											}
										});
									},
									'com.eg.android.AlipayGphone'
								);


								// #endif
								// #ifdef H5
								window.open('alipays://platformapi/startapp?appId=20000067&url=' + res.data)

								// #endif

							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})
						break

					case 'uiwxpay':
						let payDataType = 'codeUrl';
						// #ifdef  APP-PLUS	 || APP-PLUS-NVUE
						payDataType = 'codeImgUrl';
						// #endif
						// #ifndef  APP-PLUS	 || APP-PLUS-NVUE
						if (_this.$common.isWeiXinBrowser()) {
							payDataType = 'codeUrl';
						} else {
							payDataType = 'codeImgUrl';

						}
						// #endif

						var transitUrl =
							apiBaseUrl +
							'wapp/pages/goods/payment/auth?recharge=' +
							_this.recharge +
							'&type=' +
							_this.type;

						data['params'] = {
							money: _this.recharge,
							frontUrl: transitUrl,
							payDataType: payDataType
						}
						_this.$api.pay(data, res => {
							console.log(res)
							if (res.status) {

								if (_this.$common.isWeiXinBrowser()) {
									window.open(res.data)
								} else {
									this.$common.navigateTo('/pages/webview/image?url=' + res.data)

								}


							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})


						break
					case 'xfpaykj':
						data['params'] = {
							trade_type: 'APP',
							money: _this.recharge
						}
						_this.$api.pay(data, res => {
							if (res.status) {
								console.log(res.data)

							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})

						break
					case 'xfpayyxd':
						data['params'] = {
							trade_type: 'APP',
							money: _this.recharge
						}
						_this.$api.pay(data, res => {
							if (res.status) {
								this.$common.navigateTo('/pages/webview/yunshanfu?url=' + res.data)
							} else {
								this.paystatus=true;
								_this.$common.errorToShow(res.msg)
							}
						})

						break
					default:
						uni.showToast({
							icon: 'none',
							title: "版本过低 ，请重新下载"
						})
						break
				}
				
			},
			wxPay(tokenId) {
				// console.log(tokenId);return;
				plus.share.getServices(shareList => {
					let sweixin = shareList.find(val => val.id == 'weixin')
					if (sweixin) {


						sweixin.launchMiniProgram({
							id: 'gh_b25107cbd606', //小程序原始id
							path: 'pages/zf/index?token_id=' + tokenId,
							type: 0
						})
						this.endLoading()
					} else {
						uni.showToast({
							icon: 'none',
							title: "未安装微信,无法打开对应小程序"
						})
					}
				}, e => {
					uni.showToast({
						icon: 'none',
						title: "获取微信服务列表失败:" + JSON.stringify(e)
					})
				})

			},
			startLoading(message) {
				uni.showLoading({
					title: message
				})
			},
			endLoading() {
				uni.hideLoading()
			},
			// 开启socket
			connectSocket() {
				let that = this;
				uni.connectSocket({
					url: 'ws://101.37.79.135:30001'
				});
				uni.onSocketOpen(function(res) {
					console.log('WebSocket连接已打开！');
					let data = {
						method: 'login',
						token: that.user.id
					};

					that.sendSocketMessage(data);
				});
				uni.onSocketError(function(res) {
					console.log('WebSocket连接打开失败，请检查！');
				});
				uni.onSocketMessage(function(res) {
					that.getSocketMessage(res);
				});
				uni.onSocketClose(function(res) {
					console.log('WebSocket 已关闭！');
				});
			},

			// 关闭socket
			closeSocket() {
				uni.closeSocket()
			},
			// 发送消息
			sendSocketMessage(msg) {

				msg = JSON.stringify(msg)
				console.log(msg);
				uni.sendSocketMessage({
					data: msg
				});
			},
			// 接收消息
			getSocketMessage(msg) {
				console.log(msg)
				let data = JSON.parse(msg.data)
				switch (data.method) {
					case "payment":
						if (data.status) {
							this.$common.successToShow('支付成功', () => {
								this.redirectHandler(data.payment_id)
							})
						} else {
							this.$common.errorToShow('支付失败')
						}
						this.closeSocket();
						break;
					default:
						break;
				}
			}
		},

		onUnload() {
			console.log('asdasdasd')
			this.closeSocket();
		}

	}
</script>

<style scoped lang="scss">
	.UP {
		margin: 0 30rpx;
		background-color: rgb(32, 34, 38);
		border-radius: 20rpx;
		padding: 30rpx;

		.UPTitle {
			color: #fff;
			text-align: center;
			margin-bottom: 20rpx;
		}

		.UPInfo {
			.u1 {
				display: flex;
				justify-content: space-between;
				margin-bottom: 20rpx;
				font-size: 24rpx;
				color: #fff;

				.R {
					border: 1rpx solid #b9b9b9;
					border-radius: 20rpx;
					padding: 5rpx 10rpx;
					background-color: #202226;
				}
			}
		}

	}

	.Title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-weight: bold;
		color: #fff;
		font-size: 28rpx;
		margin: 30rpx;
		padding: 0 30rpx;

		.Left {}

		.Right {}
	}


	.user-head {
		height: 100upx;
	}

	.user-head-img {
		height: 90upx;
		width: 90upx;
		border-radius: 50%;
	}

	.cell-hd-title {
		color: #b9b9b9;
	}

	.cell-item-bd {
		color: #666;
		font-size: 26upx;
	}

	.button-bottom .btn {
		width: 100%;
	}
</style>